package com.ktjy.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ktjy.dto.ClueTrackRecordDTO;
import com.ktjy.pojo.TbClueTrackRecord;
import com.ktjy.service.ITbClueTrackRecordService;
import com.ktjy.utils.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 线索跟进记录 前端控制器
 * </p>
 *
 * @author jjx
 * @since 2025-08-19
 */
@RestController
@Slf4j
@Tag(name="线索跟进记录")
@RequestMapping("/api/tb/clueRecord")
public class TbClueTrackRecordController {
    @Autowired
    private ITbClueTrackRecordService clueTrackRecordService;

    @Operation(summary = "查询线索跟进记录列表")
    @GetMapping("/list")
    public AjaxResult list(ClueTrackRecordDTO clueTrackRecordDTO,
                           @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        IPage<TbClueTrackRecord> page = clueTrackRecordService.findPage(clueTrackRecordDTO, pageNo, pageSize);
        return AjaxResult.success(page);
    }

    @Operation(summary = "新增线索跟进记录")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody ClueTrackRecordDTO clueTrackRecordDTO){
        try {
            clueTrackRecordService.saveTrackRecord(clueTrackRecordDTO);
            return AjaxResult.success("保存成功");
        } catch (Exception e) {
            log.error("TbClueController中save方法执行报错的。",e);
        }
        return AjaxResult.error("保存失败");
    }
}
